package com.twb.auth.service.impl;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.twb.auth.entity.twbOnline.TwbOnline;
import com.twb.auth.entity.twbOnline.dto.SearchTwbOnlineDto;
import com.twb.auth.entity.twbOnline.vo.SearchTwbOnlineVo;
import com.twb.auth.mapper.TwbOnlineMapper;
import com.twb.auth.service.ITwbOnlineService;
import com.twb.core.base.entity.TwbPageInfo;
import com.twb.core.base.service.impl.BaseService;
import com.twb.core.util.ExcelUtils;
import com.twb.core.util.TwbPageUtil;
import com.twb.system.util.ExcelDataDicHandlerImpl;

/**
 * @ClassName twbOnlineService
 * @Description 日志管理service
 * @author DSY
 * @date 2018年11月3日 下午10:13:20
 */
@Service("twbOnlineService")
public class TwbOnlineService extends BaseService<TwbOnlineMapper,TwbOnline> implements ITwbOnlineService {

	@Autowired
	TwbOnlineMapper twbOnlineMapper;

	@Override
	public TwbPageInfo<SearchTwbOnlineDto> searchTwbOnline(SearchTwbOnlineVo vo) {
		TwbPageUtil.startPage(vo);
		List<SearchTwbOnlineDto> list = twbOnlineMapper.searchTwbOnline(vo);
		return TwbPageUtil.of(list);
	}

	@Override
	public boolean saveTwbOnline(TwbOnline online) {
		online.setId(getUUID());
		return this.save(online);
	}

	@Override
	public void exportExcel(SearchTwbOnlineVo vo, HttpServletResponse response) throws Exception {
		String fileName = vo.getFileName();
		if (StringUtils.isBlank(fileName)) {
			fileName = "登录日志信息";
		}
		TwbPageInfo<SearchTwbOnlineDto> pageInfo = this.searchTwbOnline(vo);
		List<SearchTwbOnlineDto> list = pageInfo.getList();
		ExcelDataDicHandlerImpl excelDataDicHandlerImpl = new ExcelDataDicHandlerImpl();
		ExcelUtils.exportExcel(fileName, list, SearchTwbOnlineDto.class, response, excelDataDicHandlerImpl);
	}

}
